Imports System.Configuration.ConfigurationManager

Partial Class Admin_QueryManagement
    Inherits System.Web.UI.Page

    Private _data_querylist As DS_querylist

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            Session.Item("QueryStepSelected") = 2
            LoadQuery()
        End If
        _data_querylist = Session.Item("DS_querylist")

    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim dr_qrl As DS_querylist.TBL_querystructRow

        dr_qrl = _data_querylist.TBL_querystruct.FindByQRS_codice(Session.Item("QueryStepSelected"))
        TXB_conn_string.Text = dr_qrl.QRS_connectionstring
        TXB_query_file.Text = dr_qrl.QRS_filename
        'TXB_query_string.Text = dr_qrl.QRS_stringa

        RDB_query_String.Checked = TXB_query_string.Text > ""
        RDB_query_String.AutoPostBack = Not RDB_query_String.Checked
        RDB_file_query.Checked = Not RDB_query_String.Checked
        RDB_file_query.AutoPostBack = Not RDB_file_query.Checked

        BTN_query_load_file.Enabled = RDB_file_query.Checked
        BTN_query_view.Enabled = RDB_file_query.Checked


    End Sub

    Private Sub LoadQuery()

        _data_querylist = New DS_querylist
        If System.IO.File.Exists(Server.MapPath(AppSettings.Get("TBLquerylist"))) Then
            _data_querylist.ReadXml(Server.MapPath(AppSettings.Get("TBLquerylist")))
        End If
        Session.Item("DS_querylist") = _data_querylist

    End Sub

    Protected Sub BTN_check_conndb_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_check_conndb.Click

        Session.Item("TstConneString") = TXB_conn_string.Text
        Response.Write("<script>")
        Response.Write("window.open('ConnStringCheck.aspx','_blank')")
        Response.Write("</script>")

    End Sub

    Protected Sub BTN_query_view_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_query_view.Click

        Session.Item("ViwQueryFileName") = String.Concat(AppSettings.Get("QueryStorePath"), TXB_query_file.Text)
        Response.Write("<script>")
        Response.Write("window.open('ViewQueryFile.aspx','_blank')")
        Response.Write("</script>")

    End Sub
End Class
